#include "facade_grammar.h"

#include <boost/test/included/unit_test.hpp>

void test_facade_grammar() {
	std::string grammar_file = "test_data/grammar.json";
	FacadeGrammar facade_grammar;
	Status status = facade_grammar.ReadGrammar(grammar_file);
	if (!status.IsOk())
		BOOST_ERROR(status.GetDescription());
	
	BOOST_CHECK_EQUAL(facade_grammar.get_atom_symbol(), "facade");
	std::vector<std::string> terminals = facade_grammar.get_terminal_symbols();
	BOOST_CHECK_EQUAL(terminals.size(), 2);
	BOOST_CHECK_EQUAL(facade_grammar.get_terminal_symbol_size(), 2);
	BOOST_CHECK_EQUAL(facade_grammar.get_terminal_symbol(0), "window");
	BOOST_CHECK_EQUAL(facade_grammar.get_terminal_symbol(1), "wall");
	BOOST_CHECK_EQUAL(facade_grammar.get_terminal_symbol_index("window"), 0);
	BOOST_CHECK_EQUAL(facade_grammar.get_terminal_symbol_index("wall"), 1);
	
	std::vector<double> window_color = facade_grammar.get_symbol_color("window");
	std::vector<double> wall_color = facade_grammar.get_symbol_color("wall");
	BOOST_CHECK_EQUAL(window_color.size(), 3);
	BOOST_CHECK_EQUAL(wall_color.size(), 3);
	
	BOOST_CHECK_EQUAL(facade_grammar.get_unterminal_symbol_size(), 4);
	BOOST_CHECK_EQUAL(facade_grammar.get_unterminal_symbol(0), "facadeWall");
	BOOST_CHECK_EQUAL(facade_grammar.get_unterminal_symbol(1), "facadeFloor");
	BOOST_CHECK_EQUAL(facade_grammar.get_unterminal_symbol(2), "floorWall");
	BOOST_CHECK_EQUAL(facade_grammar.get_unterminal_symbol(3), "floorWindow");
	BOOST_CHECK_EQUAL(facade_grammar.get_unterminal_symbols().size(), 4);
	
	BOOST_CHECK_EQUAL(facade_grammar.get_grammar_number(), 5);
	BOOST_CHECK_EQUAL(facade_grammar.get_symbol_apply_direction("facadeWall"), 0);
	BOOST_CHECK_EQUAL(facade_grammar.get_symbol_apply_direction("facadeFloor"), 0);
	BOOST_CHECK_EQUAL(facade_grammar.get_symbol_apply_direction("floorWall"), 1);
	BOOST_CHECK_EQUAL(facade_grammar.get_symbol_apply_direction("floorWindow"), 1);
	
	ShapeGrammar grammar = facade_grammar.get_grammar(4);
	BOOST_CHECK_EQUAL(grammar.name_, "floorWindow -> window + floorWall");
	BOOST_CHECK_EQUAL(grammar.apply_direction_, 1);
	BOOST_CHECK_EQUAL(grammar.left_hand_symbol_, "floorWindow");
	BOOST_CHECK_EQUAL(grammar.right_hand_symbol1_, "window");
	BOOST_CHECK_EQUAL(grammar.right_hand_symbol2_, "floorWall");
	BOOST_CHECK_EQUAL(grammar.exception_symbol_, "wall");
	BOOST_CHECK_EQUAL(grammar.value_parameter_[0], 12);
	BOOST_CHECK_EQUAL(grammar.value_parameter_[1], 14);
	BOOST_CHECK_EQUAL(grammar.value_parameter_[2], 16);
	
}